package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.Auth;
import com.atguigu.crowd.entity.AuthExample;
import com.atguigu.crowd.mapper.AuthMapper;
import com.atguigu.crowd.service.api.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AuthServiceImpl implements AuthService {

	@Autowired
	private AuthMapper authMapper;


	/**
	 * 查询出 Auth表的所有的数据
	 * @return
	 */
	@Override
	public List<Auth> getAll() {
		
		return authMapper.selectByExample(new AuthExample());
	}
	
	@Override
	public List<Auth> getAllBySql() {
		return authMapper.selectAllBySql();
	}

	/**
	 * 【实现类】查询出 Auth表的所有的数据  自己写sql不要框架的方法
	 * @return
	 */
	@Override
	public List<Integer> getAssignedAuthIdByRoleId(Integer roleId) {
		
		return authMapper.selectAssignedAuthIdByRole(roleId);
	}
	@Override
	public void savaRoleAuthRelathinShip(Map<String, List<Integer>> map) {

		//1、获取roleId的值
		List<Integer> roleIdList=map.get("roleId");
		Integer roleId=roleIdList.get(0);

		//2、根据角色id，删除旧的关联关系
		authMapper.deleteOldRelationship(roleId);

		//获取authIdList
		List<Integer> authIdList=map.get("authIdArray");

		// 判断 authIdList是否有效
		if (authIdList != null && authIdList.size() > 0){

			//3、插入/新增 新的关联关系
			authMapper.insertNewRelationship(roleId,authIdList);
		}
	}

	@Override
	public List<String> getAssignedAuthByAdminId(Integer adminId) {
		// TODO Auto-generated method stub
		return authMapper.selectAssignedAuthByAdminId(adminId);
	}


}




















